﻿namespace net.zxteam.ZXLexer.Runtime.Internal
{
	using System;
	using System.IO;

	internal class LexerSource : TextReader
	{
		private readonly StateTextReader _stateTextReader;

		public LexerSource(TextReader input)
		{
			this._stateTextReader = new StateTextReader(input);
		}

		public LexerStateScope CreateStateScope() { return _stateTextReader.CreateStateScope(); }
		public IDisposable CreateIndentScope() { return null; }


		public char ReadChar()
		{
			int ch = Peek();
			return (char)ch;
		}
		//bool HasChars { get; }

		public int Position { get { return _stateTextReader.Position;  } }
		public int StateInitPosition
		{
			get
			{
				var stateScope = _stateTextReader.TopStateScope;
				if (stateScope != null)
					return stateScope.InitPosition;

				return this.Position;
			}
		}
	}
}
